<?php

namespace support\middleware;

use Webman\MiddlewareInterface;
use Webman\Http\Response;
use Webman\Http\Request;

class AccessControl implements MiddlewareInterface
{
    public function process(Request $request, callable $next) : Response
    {
        $response = $request->method() == 'OPTIONS' ? response('') : $next($request);
        $response->withHeaders([
//            'Access-Control-Allow-Credentials' => true,
            'Access-Control-Allow-Origin' => '*',
            'Access-Control-Allow-Methods' => 'GET,POST,OPTIONS',
            'Access-Control-Expose-Headers' => 'appid,authorization,content-type',
            'Access-Control-Allow-Headers' => 'appid,authorization,content-type'
        ]);

        return $response;
    }
}